/**
 * Created by wangjiaxin on 16/10/22.
 * @description 客户信息service
 */
import {Injectable} from "@angular/core";
import {MdDialog, MdDialogConfig} from "@angular/material";
import {Observable} from "rxjs/Observable";
import {TipComponent} from '../../module/dialog/tip/tip.component';
import {PlaintextComponent} from '../../module/dialog/plaintext.component';
import {CityPickerComponent} from '../../module/city-picker/city-picker.component';

@Injectable()
export class MdDialogService{

  constructor(private mdDialog : MdDialog) { }

  //封装confirm，直接返回订阅对象
  /**
   * 对话框
   *
   * @param {string} tipText
   * @returns {Observable<any>}
   */
  confirm(tipText : string,needEdit ?:boolean) : Observable<any>{
    let config = new MdDialogConfig();
    config.data = {
        tipText : tipText,
    }
    return this.mdDialog.open(TipComponent, config).afterClosed();
  }


  //提示
  /**
   * 提示框
   *
   * @param {string} tipText 提示语
   * @param {boolean} timeout 是否需要定时自动关闭
   * @param {boolean} needEdit 是否需要输入备注信息输入框
   * @returns {Observable<any>}
   */
  tip(tipText :string, timeout ?:boolean,needEdit ?:boolean) : Observable<any>{
    let config = new MdDialogConfig();
    config.data = {
      tipText : tipText,
      timeout : timeout,
      needEdit : needEdit,
    }
    return this.mdDialog.open(TipComponent, config).afterClosed();
  }

  /**
   * 提示框222
   *
   * @param {string} tipText
   * @returns {Observable<any>}
   */
  plainTip(tipText : string,backgroundColor?:string) : Observable<any>{
    let config = new MdDialogConfig();
    config.data = {
      tipText : tipText,
      backgroundColor : backgroundColor,
    };
    return this.mdDialog.open(PlaintextComponent, config).afterClosed();
  }
  /**
   * 省市区 -- 可以扩展加code
   *
   * @param {string} province
   * @param {string} city
   * @param {string} county
   * @returns {Observable<any>}
   */
  cityPicker(province:string,city:string,county:string):  Observable<any>{
    let config = new MdDialogConfig();
    config.data = {
      province : province,
      city : city,
      county : county,
    }
    return this.mdDialog.open(CityPickerComponent, config).afterClosed();
  }



}
